/*
 * FileSystemTableModel.java
 *
 * Created on December 7, 2006, 10:47 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package eu.somatik.somaftp.gui.logic;

import eu.somatik.somaftp.logic.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author francisdb
 */
public class FileSystemTableModel extends AbstractTableModel{
    
    private static final String[] HEADERS = new String[]{"Name", "Size"};
    private static final Class[] CLASSES = new Class[]{FileInterface.class, FileSize.class};
    
    private List<FileInterface> items;
    
    
    /** Creates a new instance of FileSystemTableModel */
    public FileSystemTableModel() {
        this.items = new ArrayList<FileInterface>();
    }
    
    public void setFiles(List<FileInterface> files){
        this.items = files;
        fireTableDataChanged();
    }
    
    public void clear(){
        setFiles(new ArrayList<FileInterface>());
    }

    public int getRowCount() {
        return items.size();
    }

    public int getColumnCount() {
        return HEADERS.length;
    }
    
    public String getColumnName(int columnIndex){
        return HEADERS[columnIndex];
    }

    public Class getColumnClass(int columnIndex){
        return CLASSES[columnIndex];
    }
    
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 0:
                return items.get(rowIndex);
            case 1:
                long size = items.get(rowIndex).getSize();
                if(size == -1){
                    return null;
                }else{
                    return new FileSize(items.get(rowIndex).getSize());
                }
            default:
                assert false: "Should never come here";
        }
        return null;
    }
    
    
    

    
}
